package com.qdxwx.web.controller.help;

import com.qdxwx.common.utils.TKConvert;
import com.qdxwx.data.service.help.HelpService;
import com.qdxwx.models.help.Help;
import com.qdxwx.web.controller.BaseController;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import jakarta.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 前台 controller
 * @author developer
 */
@Controller
@RequestMapping("/help")
public class HelpCenterController extends BaseController {

	private static final Logger logger = LoggerFactory.getLogger(HelpCenterController.class);

	@Autowired
	private HelpService helpService;

	/**
	 * 帮助中心
	 */
	@RequestMapping("/index.html")
	public String getHelpCenter(HttpServletRequest request, ModelMap model) {
		long id = TKConvert.toLong(request.getParameter("id"));
		if (id < 1) {
			id = 1;
		}
		// 帮助中心菜单集合，不含内容
		List<List<Help>> helpMenus = helpService.getAll();
		// 右侧显示内容
		Help helpMenuContent = helpService.get(id);
		if (helpMenuContent == null) {
			return toError404(request);
		}
		model.put("helpMenus", helpMenus);
		model.put("helpMenuContent", helpMenuContent);//显示的
		return getViewPath("help/help-index");
	}
}